#include "Playbook.h"

Playbook::Playbook()
{
	int t_numberOfMoves = 0;
	std::list<Square*> *t_previousMoves = new std::list<Square*>;
	Square *t_resultingMove = new Square(9, 9);
	AddPlay(*t_previousMoves, t_resultingMove);
}

Playbook::~Playbook()
{
	for(std::list<Play*>::iterator it = m_plays.begin(); it != m_plays.end(); it++)
	{
		delete *it;
	}
}

void Playbook::AddPlay(std::list<Square*> previousMoves, Square *resultingMove)
{
	Play *t_play = new Play;

	t_play->PreviousMoves = previousMoves;
	t_play->ResultingMove = resultingMove;

	m_plays.push_back(t_play);
}

bool Playbook::CheckForMove(std::list<Square*> previousMoves, Move &out)
{
	for(std::list<Play*>::iterator it = m_plays.begin(); it != m_plays.end(); it++)
	{
		// Delete obslete plays to increase speed
		while(previousMoves.size() > (*it)->PreviousMoves.size())
		{
			delete *it;
			it = m_plays.erase(it);
		}

		// Number of moves match, check moves are equivalent
		if(previousMoves.size() == (*it)->PreviousMoves.size())
		{
			bool t_directMatch = true;
			bool t_horizontalFlipMatch = true;
			bool t_verticalFlipMatch = true;
			bool t_doubleFlipMatch = true;


			for(std::list<Square*>::iterator it2 = previousMoves.begin(); it2 != previousMoves.begin(); it2++)
			{
				for(std::list<Square*>::iterator it3 = (*it)->PreviousMoves.begin(); it3 != (*it)->PreviousMoves.end(); it3++)
				{
					// Check Direct Match
					
				}
			}
		}
	}
	return false;
}